package com.baizhi.service.impl;

import com.baizhi.dao.FunctionDao;
import com.baizhi.dao.UserDao;
import com.baizhi.Auction;
import com.baizhi.User;
import com.baizhi.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao us;
    @Autowired
    private FunctionDao fd;
    @Override
    public boolean login(String name, String pwd) {
        int i = us.selectId(name);
        User user = us.selectById(i);
        System.out.println(user);
        if (user==null){
            return false;
        }else if (name.equals(user.getUser_name())&&pwd.equals(user.getUser_password())){
            return true;
        }
        return false;
    }

    @Override
    public boolean register(User u) {
        Integer insert = us.insert(u);
        if (insert!=0){
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<Auction> page(int pageSize, int pageIndex) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Auction> auctions = fd.selectList(null);
        PageInfo<Auction> page= new PageInfo<Auction>(auctions);
        return page;
    }

    public UserDao getUs() {
        return us;
    }

    public void setUs(UserDao us) {
        this.us = us;
    }
}
